#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：17.异步迭代器.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-08 15:29
'''
import asyncio


class Reader:
    def __init__(self):
        self.count = 0

    async def read_line(self):
        self.count += 1
        if self.count == 101:
            return None
        return self.count


    # 异步迭代器只是普通函数
    def __aiter__(self):
        return self

    async def __anext__(self):
        value = await self.read_line()
        if value is None:
            raise StopIteration # 异步迭代异常
        return value


async def main():
    async for item in Reader():
        print(item)

asyncio.run(main())